package oa.mhm.service.Comresource;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oa.dao.ComResourceDao;
import oa.pojo.ComResource;

public class GetComNameServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ComResourceDao comdao = new ComResourceDao();
		String comtype = request.getParameter("comtype11");
		List<ComResource> comlist = comdao.selectCom_Fine(comtype);
		StringBuffer buff = new StringBuffer();
		buff.append("<comresources>");
		Iterator<ComResource> itr = comlist.iterator();
		while (itr.hasNext()) {
			ComResource com = itr.next();
			buff.append("<comresource>").append("<id>").append(com.getCrId())
					.append("</id>").append("<name>").append(com.getCrName())
					.append("</name>").append("<price>").append(
							com.getCrPrice()).append("</price>").append(
							"<condition>").append(com.getCrCondition()).append(
							"</condition>").append("</comresource>");
		}
		buff.append("</comresources>");
		response.setContentType("text/xml;charset=utf-8");
		PrintWriter pw = response.getWriter();
		pw.println(buff.toString());
		pw.flush();
	}

}
